package com.newland.nxsms.cmpp;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.newland.nxsms.kafka.KafkaProducer;

public class SetData implements Runnable {
	public static final Logger log = LoggerFactory.getLogger(SetData.class);
	private KafkaProducer kafkaProducer;
	private String bootstrap;
	private String topic;
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public SetData(String bootstrap,String topic) {
		this.bootstrap = bootstrap;
		this.topic = topic;
	}
	
	private void init() {
		kafkaProducer = new KafkaProducer(bootstrap);
		kafkaProducer.setAcks("0");
		kafkaProducer.connect();
	}
	@Override
	public void run() {
		init();
		log.info("set DATA start");
		String msg = "19533481668%_%checkRealSms%_%"+sdf.format(new Date());
		try {
			for (int i = 0; i < 1; i++) {
				kafkaProducer.send(topic, msg.getBytes());
			}
		} catch (Exception e) {
			close();
			log.error("set data error"+e);
		}
		
		close();
	}
	private void close(){
		if (null != kafkaProducer) {
			kafkaProducer.close();
		}
	}

}
